package by.onlinernews.loader;

import java.io.ByteArrayOutputStream;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.Log;
import by.onlinernews.newsfull.FullNewsActivity;

public class LoadImageInText extends ImageLoadHelper implements Runnable {
	String link;
	int page;
	Context ctx;

	public LoadImageInText(String link, int page, Context ctx) {
		Log.d("drawable","link " + link); 
		this.link = link;
		Log.d("drawable","get ctx"); 
		this.ctx = ctx;
		Log.d("drawable","page " + page); 
		this.page = page;
	}

	@Override
	public void run() {
		Log.d("drawable","start"); 
		Bitmap bitmap = LoadImage(link);
		Log.d("drawable","load bitmap"); 
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
		Log.d("drawable","bitmap to byte"); 
		byte[] b = baos.toByteArray();	
		Log.d("drawable","send broadcast"); 
		ctx.sendBroadcast(new Intent(
				FullNewsActivity.BROADCAST_ACTION)
				.putExtra("flag", FullNewsActivity.SET_IMAGE_IN_TEXT)
				.putExtra("pageNumber", page)
				.putExtra("link", link)
				.putExtra("bitmap", b));
		
		
	}

}
